import heapq
from math import pi,sqrt,ceil,floor,log2,log10
from collections import deque,defaultdict,Counter
from sys import setrecursionlimit
setrecursionlimit(1_000_000)
def gcd(a,b):
while(b):
a,b = b,a % b
return a
def lcm(a,b):
return a * b // gcd(a,b)
def minput():
return map(int,input().split())
def linput():
return list(map(int,input().split()))
MOD = int(1e9) + 7
sz = int(1e5) + 5
INT_MAX = float('inf')
def solve():
n,m = minput()
arr = [linput() for _ in range(2)]
sum = 0
res = INT_MAX
for i in range(n - 1,-1,-1):
if(i + 1 <= m):
res = min(res,sum + arr[0][i])
sum += min(arr[0][i],arr[1][i])
print(res)
def main():
t = int(input())
for _ in range(t):
solve()
if __name__ == '__main__':
main()
102. Binary Tree Level Order Traversal | 96. Unique Binary Search Trees |
75. Sort Colors | 74. Search a 2D Matrix |
71. Simplify Path | 62. Unique Paths |
50. Pow(x, n) | 43. Multiply Strings |
34. Find First and Last Position of Element in Sorted Array | 33. Search in Rotated Sorted Array |
17. Letter Combinations of a Phone Number | 5. Longest Palindromic Substring |
3. Longest Substring Without Repeating Characters | 1312. Minimum Insertion Steps to Make a String Palindrome |
1092. Shortest Common Supersequence | 1044. Longest Duplicate Substring |
1032. Stream of Characters | 987. Vertical Order Traversal of a Binary Tree |
952. Largest Component Size by Common Factor | 212. Word Search II |
174. Dungeon Game | 127. Word Ladder |
123. Best Time to Buy and Sell Stock III | 85. Maximal Rectangle |
84. Largest Rectangle in Histogram | 60. Permutation Sequence |
42. Trapping Rain Water | 32. Longest Valid Parentheses |
Cutting a material | Bubble Sort |